`
https://leetcode.cn/problems/longest-increasing-subsequence/
`

/**
 * @param {number[]} nums
 * @return {number}
 */
var lengthOfLIS = function (nums) {
  // 具体的思路可参照
  // https://labuladong.online/algo/dynamic-programming/longest-increasing-subsequence/#%E4%BA%8C%E3%80%81%E4%BA%8C%E5%88%86%E6%9F%A5%E6%89%BE%E8%A7%A3%E6%B3%95
  const top = new Array(nums.length);
  // 牌堆数初始化为 0
  let piles = 0
  for (let i = 0; i < nums.length; i++) {
    // 要处理的扑克牌
    const poker = nums[i]

    // ***** 搜索左侧边界的二分查找 *****
    let left = 0, right = piles
    while (left < right) {
      const mid = Math.floor((left + right) / 2)
      if (top[mid] < poker) {
        left = mid + 1
      } else {
        right = mid
      }
    }

    // 没找到合适的牌堆，新建一堆
    if (left == piles) piles++
    // 把这张牌放到牌堆顶
    top[left] = poker
  }
  // 牌堆数就是 LIS 长度
  return piles
};